﻿//Created by Action Script Viewer - http://www.buraks.com/asv
package zasp.Classes {
    import flash.display.*;
    import flash.utils.*;
    import flash.system.*;
    import zasp.Util.*;

    public class ZaspTrackerBase {

        protected static const ALPHA:Number = 0.07;

        protected var sma_dt:Number = 5000;
        protected var totalDt:int = 0;
        protected var totalNum:int = 0;
        protected var gameState:String = "";
        protected var gameNumber:Number = 0;
        protected var objectCount:int = 0;
        protected var emaF2F:EMA;
        protected var emaOEF:EMA;
        protected var emaMEM:EMA;
        protected var sum5sF2F:SumSampler = null;
        protected var detailTracker:ZaspTrackerDetail = null;
        protected var debugTracker:ZaspTrackerDebug = null;
        private var m_sessionid:String;

        public function ZaspTrackerBase(_arg1:String, _arg2:int=5000){
            this.emaF2F = new EMA(ALPHA);
            this.emaOEF = new EMA(ALPHA);
            this.emaMEM = new EMA(ALPHA);
            super();
            this.sma_dt = _arg2;
            this.m_sessionid = _arg1;
            this.sum5sF2F = new SumSampler(this.sma_dt);
        }
        public function sample(_arg1:Number, _arg2:Number):void{
            var _local3:int = System.totalMemory;
            this.totalDt = getTimer();
            this.totalNum++;
            this.emaF2F.sample(_arg1);
            this.emaOEF.sample(_arg2);
            this.emaMEM.sample(_local3);
            this.sum5sF2F.sample(_arg1);
            if (this.detailTracker){
                this.detailTracker.sample(this.gameState, this.gameNumber, _arg1, _local3);
            };
            if (this.debugTracker){
                this.debugTracker.sample(_arg1, _arg2);
            };
        }
        public function activateDetailTracking():void{
            this.detailTracker = new ZaspTrackerDetail();
        }
        public function isDetailActive():Boolean{
            return (!((this.detailTracker == null)));
        }
        public function activateDebugTracking(_arg1:DisplayObjectContainer=null, _arg2:Boolean=false):void{
            this.debugTracker = new ZaspTrackerDebug(this, _arg2);
            if (_arg1){
                _arg1.addChild(this.debugTracker.sprite);
                this.debugTracker.activateSpinners();
            };
        }
        public function report():Object{
            var _local4:Number;
            var _local1:Object = new Object();
            _local1.type = "fps";
            _local1.constants = ((("Alpha:" + ALPHA) + " SMA_DT:") + this.sma_dt);
            _local1.totalDt = this.totalDt;
            _local1.totalNum = this.totalNum;
            _local1.ema_mem = this.emaMEM.value;
            _local1.game_state = this.gameState;
            _local1.game_number = this.gameNumber;
            _local1.object_count = this.objectCount;
            _local1.sessionid = this.m_sessionid;
            var _local2:Number = this.emaF2F.value;
            _local1.ema_f2f_dt = _local2;
            if (_local2 > 0){
                _local1.ema_f2f_fps = (1000 / _local2);
            };
            var _local3:Number = this.emaOEF.value;
            _local1.ema_oef_dt = _local3;
            if (_local3 > 0){
                _local1.ema_oef_fps = (1000 / _local3);
            };
            if (this.sum5sF2F.length > 0){
                _local4 = (this.sum5sF2F.value / this.sum5sF2F.length);
                _local1.s5s_f2f_dt = _local4;
                if (_local4 > 0){
                    _local1.s5s_f2f_fps = (1000 / _local4);
                };
            };
            if (this.detailTracker){
                _local1.detail = this.detailTracker.report();
            };
            return (_local1);
        }
        public function get f2f():Number{
            return (this.emaF2F.value);
        }
        public function get f2f5s():Number{
            return ((this.sum5sF2F.value / this.sum5sF2F.length));
        }
        public function get oef():Number{
            return (this.emaOEF.value);
        }
        public function get mem():Number{
            return (this.emaMEM.value);
        }
        public function setGameState(_arg1:String="", _arg2:Number=0):void{
            this.gameState = _arg1;
            this.gameNumber = _arg2;
        }
        public function setObjectCount(_arg1:int=0):void{
            this.objectCount = _arg1;
        }
        public function log_report():void{
            var _local3:Number;
            trace("PERFORMANCE REPORT BASE");
            trace(("  ALPHA:         " + ALPHA));
            trace(("  SMA_DT:        " + this.sma_dt));
            trace(("  totalDt:       " + this.totalDt));
            trace(("  totalNum:      " + this.totalNum));
            trace(("  ema_mem:       " + this.emaMEM.value));
            var _local1:Number = this.emaF2F.value;
            trace(("  ema_f2f_dt:  " + _local1));
            trace(("  object count: " + this.objectCount));
            if (_local1 > 0){
                trace(("  ema_f2f_fps:   " + (1000 / _local1)));
            };
            var _local2:Number = this.emaOEF.value;
            trace(("  ema_oef_dt:    " + _local2));
            if (_local2 > 0){
                trace(("  ema_oef_fps:   " + (1000 / _local2)));
            };
            if (this.sum5sF2F.length > 0){
                _local3 = (this.sum5sF2F.value / this.sum5sF2F.length);
                trace(("  5s_f2f_dt:     " + _local3));
                if (_local3 > 0){
                    trace(("  5s_f2f_fps:    " + (1000 / _local3)));
                };
            };
            if (this.detailTracker){
                this.detailTracker.log_report();
            };
            if (this.debugTracker){
                this.debugTracker.log_report();
            };
        }

    }
}//package zasp.Classes 
